package com.work11;

import java.util.HashMap;
import java.util.Scanner;
import java.util.function.BiConsumer;

public class Test {
    public static void main(String[] args) {
        //1. 将以下车站对应关系的数据存储到map集合中，
        // key：表示站编号，value：表示站名，并遍历打印(可以不按顺序打印)：
        //2. 计算地铁票价规则：
        //总行程 3站内（包含3站）收费3元，
        // 3站以上但不超过5站（包含5站）的收费4元，5站以上的，在4元的基础上，每多1站增加2元，10元封顶；
        //3. 需要对键盘录入的上车站和到达站进行判断，如果没有该站，
        // 提示重新输入，直到站名存在为止,每站需要2分钟.
//        ArrayList<String> stationNames = new ArrayList<>();

        //存储了所有的站点信息
        String[] names = {"黄花机场T1T2","木马锻","大路村","龙峰","曹家坪","檀木桥","龙华",
           "韶光","东湖","农科院农大","隆平水稻博物馆","花桥","人民东路","芙蓉区政府","朝阳村",
           "窑玲湘雅二医院","迎宾路口","烈士公园南","湘雅医院","文昌阁","六沟垅","湘雅三医院",
                "白鸽咀","湖南工商大学","涧塘","麓谷公园","麓谷体育公园","长丰","和馨园","长庆",
                "师范西校区","中塘","象鼻窝","谢家桥"};
        HashMap<String, Station> stationInfoMap = new HashMap<>();
        for (int i = 0; i < names.length; i++) {
            Station station = new Station(names[i], i+1);
            String name = names[i];
            System.out.println(name);
            stationInfoMap.put(names[i],station);
        }

        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("请您输入您的上车车站");
            String statrtStationName = scanner.next();
            if(stationInfoMap.containsKey(statrtStationName)) {
                System.out.println(statrtStationName);
                System.out.println("请输入您的到站车站");
                Station startStation = stationInfoMap.get(statrtStationName);
                String arriveStationName = scanner.next();
                while (true) {
                    if(stationInfoMap.containsKey(arriveStationName)){
                        //计算价格
                        Station arriveStation = stationInfoMap.get(arriveStationName);
                        int numStation =  arriveStation.getStationCode() - startStation.getStationCode();
                        double price = 0.0;
                        if(numStation <= 3) {
                            price = 3.0;
                        } else if(numStation > 3 && numStation <= 5) {
                            price = 4.0;
                        } else if(numStation > 5) {
                            price = (4.0 + (numStation - 5) * 2) > 10 ? 10 : (4.0 + (numStation - 5) * 2);
                        }
                        System.out.println("从"+statrtStationName+"到"+arriveStationName+"共经过"+numStation+"站"+"票价为"+price+"元");

                        break;
                    }else {
                        System.out.println("站点不存在，请重新输入");
                    }
                }
                break;
            }else {
                System.out.println("站点不存在，请重新输入");
            }

        }
        System.out.println(stationInfoMap);
        stationInfoMap.forEach(new BiConsumer<String, Station>() {
            @Override
            public void accept(String s, Station station) {
                System.out.println(station.getStationCode() + "-" + s);
            }
        });
    }
}
